import math

class Node:
    name = " "
    x = 0
    y = 0

    def __init__(self,name,x,y):
        self.name = name
        self.x = x
        self.y = y



class Link:
    Distance = 0.0
    StartCity = ' '
    EndCity = ' '

    def __init__(self,Distance,StartCity,EndCity):
        self.length = Distance
        self.StartCity = StartCity
        self.EndCity = EndCity


class Graph:
    NodeList = []
    LinkList = []


    def NodeProcess(self,dataLine):
        mylist = []
        mylist = dataLine[:-1].split(";")
        print(mylist)
        n = Node(mylist[0],mylist[1],mylist[2])
        self.NodeList.append(n)

    def RoadProcess(self,dataline):
         mylist = []
         mylist = dataline[:-1].split(";")
         searchlist1 = []
         searchlist1.append(self.SearchX(mylist[0]))
         searchlist1.append(self.SearchY(mylist[0]))
         searchlist2 = []
         searchlist2.append(self.SearchX(mylist[1]))
         searchlist2.append(self.SearchY(mylist[1]))
         distance = self.CalculateDistance(int(searchlist1[0]),int(searchlist1[1]),int(searchlist2[0]),int(searchlist2[1]))
         l = Link(distance,mylist[0],mylist[1])
         self.LinkList.append(l)



    def ReadLocations(self,fileName):
        dataFile = open(fileName)
        for dataLine in dataFile.readlines():
            self.NodeProcess(dataLine)
        dataFile.close()
        del dataFile

    def ReadRoads(self,fileName):
        dataFile = open(fileName)
        for dataLine in dataFile.readlines():
            self.RoadProcess(dataLine)
        dataFile.close()
        del dataFile
    
    def CalculateDistance(self,x1,y1,x2,y2):
        xtot = x2 - x1
        ytot = y2 - y1
        Distance = math.sqrt((xtot ** 2) + (ytot ** 2))
        return Distance

    def SearchX(self,Cityname):
        for node in self.NodeList:
            if(node.name == Cityname):
                return node.x
   
    def SearchY(self,Cityname):
        for node in self.NodeList:
            if(node.name == Cityname):
                return node.y


              
            

g = Graph()
g.ReadLocations("locations.csv")
g.ReadRoads("roads-1.csv")
print(g.LinkList)